package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ICategoryService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜品及套餐分类 前端控制器
 * </p>
 *
 * @author mr.meng
 * @since 2025-10-16
 */
@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Result pageQuery(CategoryPageQueryDTO dto){
        PageResult pageResult = categoryService.pageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 新增接口
     * @param dto
     * @return
     */
    @PostMapping
    public Result add(@RequestBody CategoryDTO dto){
        categoryService.add(dto);
        return Result.success();
    }

    /**
     * 修改分类
     * @param dto
     * @return
     */
    @PutMapping
    public Result<String> update(@RequestBody CategoryDTO dto){
        categoryService.update(dto);
        return Result.success();
    }

    /**
     * 删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteById(Long id){
        Result result = categoryService.deleteById(id);
        return result;
    }

    /**
     * 启用禁用
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result<String> startOrStop(@PathVariable("status") Integer status,Long id){
        categoryService.startOrStop(status,id);
        return Result.success();
    }

    /**
     * 根据类型查询
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }
}
